import 'package:fijkplayer/fijkplayer.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:player/player.dart';

class VideoView extends StatefulWidget {
  final Player player;

  const VideoView(this.player);

  @override
  State<StatefulWidget> createState() => _VideoViewState();
}

class _VideoViewState extends State<VideoView> {
  @override
  Widget build(BuildContext context) {
    //注意这里需要scaffold包裹下,防止报错,为什么会报错?

    return Scaffold(
        body: GestureDetector(
            onTap: onTapVideo,
            child: Stack(children: [
              //AbsorbPointer事件拦截事件?
              AbsorbPointer(
                  absorbing: true, child: FijkView(player: widget.player)),
              if (widget.player.state == FijkState.paused)
                Align(
                  alignment: Alignment.center,
                  child: Image.asset(
                    'asset/images/play.png',
                    width: 70,
                    height: 70,
                  ),
                )
            ])));
  }

  void onTapVideo() {
    print('onTapVideo');
    if (widget.player.state == FijkState.paused) {
      widget.player.start();
    } else {
      widget.player.pause();
    }

    setState(() {});
  }

  @override
  void dispose() {
    super.dispose();
    widget.player.release();
  }
}
